//
// Created by vivi on 17/04/2018.
//
#include <ostream>

std::ostream & operator<<(std::ostream & os, const std::vector<float> & vf);

#include <gtest/gtest.h>
#include "core/engine/andrewsellehe.h"

using namespace std;
using namespace HairEngine;

ostream & operator<<(ostream & os, const vector<float> & vf) {
	os << "{";
	for (size_t i = 0; i < vf.size(); ++i) {
		os << vf[i];
		os << (i < vf.size() - 1 ? ", " : "}");
	}
	return os;
}

TEST(AndrewSelleHairEngineTest, TestStrandMassDistributorNormal) {
	srand(time(NULL));

	AndrewSelleHairEngine::StrandMassDistributionNormal distributor({0.7f, 0.4f, 0.3f, 0.2f, 0.1f});

	for (size_t _ = 0; _ < 1000; ++ _) {
		vector<float> strand = vector<float>(rand() % 20 + 1, 1.0f);
		for (size_t i = 0; i < min(distributor.tips.size(), strand.size()); ++i)
			strand[strand.size() - 1 - i] = distributor.tips[distributor.tips.size() - 1 - i];

		float totalSum = std::accumulate(strand.begin(), strand.end(), 0.0f);
		for (auto & s : strand)
			s /= totalSum;

		for (size_t i = 0; i < strand.size(); ++i)
				ASSERT_FLOAT_EQ(distributor(i, strand.size()), strand[i]) << "strand=" << strand << "\n"
				                                                          << "i=" << i << "\n"
				                                                          << "strand[i]=" << strand[i];
	}
}